//
//  UIFont+Extension.swift
//  FBSnapshotTestCase
//
//  Created by long0805 on 2020/5/9.
//

import UIKit

//途虎字体weight
public enum TuhuWeight: String {
    case regular
    case medium
}

//公司规范字体苹方weight
public enum StandardWeight: String {
    case regular
    case medium
    case ultralight
    case light
    case semibold
    case thin
}

//改进版
public extension UIFont {
    //情形一：公司规范字体
    
    //MARK: 情形一：公司规范字体
    /// - Parameters:
    ///   - size: 字号
    ///   - weight: StandardWeight类型 值：regular、light、medium、ultralight、semibold、thin
    class func standardFont(size: CGFloat, weight: StandardWeight) -> UIFont {
        switch weight {
        case .regular:
            // PingFangSC-Regular - 苹方-简 常规体
            return UIFont.init(name: "PingFangSC-Regular", size: size) ?? UIFont.systemFont(ofSize: size)
        case .light:
            // PingFangSC-Light - 苹方-简 细体
            return UIFont.init(name: "PingFangSC-Light", size: size) ?? UIFont.systemFont(ofSize: size)
        case .medium:
            // PingFangSC-Medium - 苹方-简 中黑体
            return UIFont.init(name: "PingFangSC-Medium", size: size) ?? UIFont.systemFont(ofSize: size)
        case .ultralight:
            //PingFangSC-Ultralight - 苹方-简 极细体
            return UIFont.init(name: "PingFangSC-Ultralight", size: size) ?? UIFont.systemFont(ofSize: size)
        case .semibold:
            // PingFangSC-Semibold - 苹方-简 中粗体
            return UIFont.init(name: "PingFangSC-Semibold", size: size) ?? UIFont.systemFont(ofSize: size)
        case .thin:
            // PingFangSC-Thin - 苹方-简 纤细体
            return UIFont.init(name: "PingFangSC-Thin", size: size) ?? UIFont.systemFont(ofSize: size)
        }
    }
    
    //MARK: 情形二：tuhu字体
    /// - Parameters:
    ///   - size: 字号
    ///   - weight: TuhuWeight类型  可以设置regular、medium
    class func tuhuFont(size: CGFloat, weight: TuhuWeight) -> UIFont {
        switch weight {
        case .medium:  // tuhumedium - 途虎粗体文字
            return UIFont.init(name: "tuhumedium", size: size) ?? UIFont.systemFont(ofSize: size)
        default:  // tuhuregular - 途虎常规文字
            return UIFont.init(name: "tuhuregular", size: size) ?? UIFont.systemFont(ofSize: size)
        }
    }
    
    //MARK: 情形三：自定义新字体
    /// - Parameters:
    ///   - fontName: 字体名称
    ///   - size: 字号
    class func customFont(fontName: String, size: CGFloat) -> UIFont {
        if let font = UIFont.init(name: fontName, size: size) {
            return font
        } else {
            return UIFont.systemFont(ofSize: size)
        }
    }
}
